/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.introduce;

import javax.swing.JOptionPane;

/**
 *
 * @author VANDH
 */
public class Dialog extends javax.swing.JFrame {

    /**
     * Creates new form Dialog
     */
    public Dialog() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgrIcon = new javax.swing.ButtonGroup();
        bgrButton = new javax.swing.ButtonGroup();
        btnInputDialog1 = new javax.swing.JButton();
        btnRegisterDialog = new javax.swing.JButton();
        btnOptionDialog = new javax.swing.JButton();
        lblConfirm = new javax.swing.JLabel();
        btnMessageDialog = new javax.swing.JButton();
        rdbInformation = new javax.swing.JRadioButton();
        rdbQuestion = new javax.swing.JRadioButton();
        rdbWarning = new javax.swing.JRadioButton();
        rdbError = new javax.swing.JRadioButton();
        btnMessageDialog1 = new javax.swing.JButton();
        rdbYesNo = new javax.swing.JRadioButton();
        rdbYesNoCancel = new javax.swing.JRadioButton();
        lblInputMessage = new javax.swing.JLabel();
        btnInputDialog2 = new javax.swing.JButton();
        lblChoiceMessage = new javax.swing.JLabel();
        lblOptionMessage = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("My Demo");

        btnInputDialog1.setText("Show InputDialog1");
        btnInputDialog1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputDialog1ActionPerformed(evt);
            }
        });

        btnRegisterDialog.setText("Open LoginDialog");
        btnRegisterDialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegisterDialogActionPerformed(evt);
            }
        });

        btnOptionDialog.setText("Show OptionDialog");
        btnOptionDialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOptionDialogActionPerformed(evt);
            }
        });

        btnMessageDialog.setText("Show MessageDialog");
        btnMessageDialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMessageDialogActionPerformed(evt);
            }
        });

        bgrIcon.add(rdbInformation);
        rdbInformation.setText("Information");

        bgrIcon.add(rdbQuestion);
        rdbQuestion.setText("Question");

        bgrIcon.add(rdbWarning);
        rdbWarning.setText("Warning");

        bgrIcon.add(rdbError);
        rdbError.setText("Error");

        btnMessageDialog1.setText("Show ConfirmDialog");
        btnMessageDialog1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMessageDialog1ActionPerformed(evt);
            }
        });

        bgrButton.add(rdbYesNo);
        rdbYesNo.setSelected(true);
        rdbYesNo.setText("Yes-No");

        bgrButton.add(rdbYesNoCancel);
        rdbYesNoCancel.setText("Yes-No-Cancel");

        btnInputDialog2.setText("Show InputDialog2");
        btnInputDialog2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputDialog2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnInputDialog2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblChoiceMessage))
                    .addComponent(btnRegisterDialog)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnMessageDialog, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnMessageDialog1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnInputDialog1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(rdbInformation)
                                    .addComponent(rdbYesNo))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(rdbQuestion)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(rdbWarning)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(rdbError))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(rdbYesNoCancel)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblConfirm))))
                            .addComponent(lblInputMessage)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnOptionDialog)
                        .addGap(18, 18, 18)
                        .addComponent(lblOptionMessage)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnInputDialog1, btnInputDialog2, btnMessageDialog, btnMessageDialog1, btnOptionDialog, btnRegisterDialog});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnMessageDialog)
                    .addComponent(rdbInformation)
                    .addComponent(rdbQuestion)
                    .addComponent(rdbWarning)
                    .addComponent(rdbError))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnMessageDialog1)
                    .addComponent(rdbYesNo)
                    .addComponent(rdbYesNoCancel)
                    .addComponent(lblConfirm))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInputDialog1)
                    .addComponent(lblInputMessage))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInputDialog2)
                    .addComponent(lblChoiceMessage))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnOptionDialog)
                    .addComponent(lblOptionMessage))
                .addGap(18, 18, 18)
                .addComponent(btnRegisterDialog)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnInputDialog1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputDialog1ActionPerformed
        String input = JOptionPane.showInputDialog(this,
                "What's your name?",
                "My Frame",
                JOptionPane.INFORMATION_MESSAGE);

        lblInputMessage.setText(input);
    }//GEN-LAST:event_btnInputDialog1ActionPerformed

    private void btnRegisterDialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegisterDialogActionPerformed
        // TODO add your handling code here:
//         Modal dialog - true, Non-modal, modaless dialog
        LoginDialog loginDialog = new LoginDialog(this, true);

        loginDialog.setVisible(true);

        String userName = loginDialog.getUserName();
        String passWord = loginDialog.getPassword();

        JOptionPane.showMessageDialog(this, userName + "\n" + passWord);
    }//GEN-LAST:event_btnRegisterDialogActionPerformed

    private void btnOptionDialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOptionDialogActionPerformed
        // TODO add your handling code here:
        Object[] values = {"Windows", "Linux", "Mac OS"};

        int option = JOptionPane.showOptionDialog(this,
                "What's your name?",
                "My Frame",
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.INFORMATION_MESSAGE,
                null,
                values,
                "Mac OS");

        lblOptionMessage.setText(values[option].toString());
    }//GEN-LAST:event_btnOptionDialogActionPerformed

    private void btnMessageDialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMessageDialogActionPerformed
        // TODO add your handling code here:
        int icon;

        if (rdbInformation.isSelected()) {
            icon = JOptionPane.INFORMATION_MESSAGE;
        } else if (rdbQuestion.isSelected()) {
            icon = JOptionPane.QUESTION_MESSAGE;
        } else if (rdbWarning.isSelected()) {
            icon = JOptionPane.WARNING_MESSAGE;
        } else if (rdbError.isSelected()) {
            icon = JOptionPane.ERROR_MESSAGE;
        } else {
            icon = JOptionPane.PLAIN_MESSAGE;
        }

        JOptionPane.showMessageDialog(this,
                "Hello everybody!",
                "My Frame", icon);
    }//GEN-LAST:event_btnMessageDialogActionPerformed

    private void btnMessageDialog1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMessageDialog1ActionPerformed
        // TODO add your handling code here:
        int icon;

        if (rdbYesNo.isSelected()) {
            icon = JOptionPane.YES_NO_OPTION;
        } else {
            icon = JOptionPane.YES_NO_CANCEL_OPTION;
        }

        int result = JOptionPane.showConfirmDialog(this,
                "Are you sure?",
                "My Frame",
                icon);

        if (result == JOptionPane.YES_OPTION) {
            lblConfirm.setText("Yes");
        } else if (result == JOptionPane.NO_OPTION) {
            lblConfirm.setText("No");
        }
        if (result == JOptionPane.CANCEL_OPTION) {
            lblConfirm.setText("Cancel");
        }
    }//GEN-LAST:event_btnMessageDialog1ActionPerformed

    private void btnInputDialog2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputDialog2ActionPerformed
        // TODO add your handling code here:
        Object[] values = {"Windows", "Linux", "Mac OS"};

        Object input = JOptionPane.showInputDialog(this,
                "What's your name?",
                "My Frame",
                JOptionPane.INFORMATION_MESSAGE,
                null,
                values,
                "Mac OS");

        lblChoiceMessage.setText(input.toString());
    }//GEN-LAST:event_btnInputDialog2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Windows look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Windows (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Dialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Dialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Dialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Dialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Dialog().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgrButton;
    private javax.swing.ButtonGroup bgrIcon;
    private javax.swing.JButton btnInputDialog1;
    private javax.swing.JButton btnInputDialog2;
    private javax.swing.JButton btnMessageDialog;
    private javax.swing.JButton btnMessageDialog1;
    private javax.swing.JButton btnOptionDialog;
    private javax.swing.JButton btnRegisterDialog;
    private javax.swing.JLabel lblChoiceMessage;
    private javax.swing.JLabel lblConfirm;
    private javax.swing.JLabel lblInputMessage;
    private javax.swing.JLabel lblOptionMessage;
    private javax.swing.JRadioButton rdbError;
    private javax.swing.JRadioButton rdbInformation;
    private javax.swing.JRadioButton rdbQuestion;
    private javax.swing.JRadioButton rdbWarning;
    private javax.swing.JRadioButton rdbYesNo;
    private javax.swing.JRadioButton rdbYesNoCancel;
    // End of variables declaration//GEN-END:variables
}
